Skip to content

feat(ddd): add DeepPrimitive type for type-safe Entity.toJSON()#73

Merged
pourdaavar merged 4 commits into
mainfrom
feat/ddd-deep-primitive-tojson
Jul 4, 2026
Merged

feat(ddd): add DeepPrimitive type for type-safe Entity.toJSON()#73
pourdaavar merged 4 commits into
mainfrom
feat/ddd-deep-primitive-tojson

Conversation

@pourdaavar

Copy link
Copy Markdown
Contributor

Summary

  • Add DeepPrimitive<T> recursive type utility mirroring Entity.normalize() runtime behavior
  • Add EntityJson<ID, Props> alias for structural toJSON() return types
  • Type Entity.toJSON() as EntityJson<ID, Props> instead of Record<string, unknown>
  • Add tsd type tests for DeepPrimitive and Entity.toJSON() shape

Closes #72

Test plan

  • pnpm test:types in packages/ddd
  • pnpm check-types in packages/ddd
  • pnpm test in packages/ddd (174 tests)
  • Pre-push turbo test suite passed

Made with Cursor

Introduce DeepPrimitive<T> and EntityJson<ID, Props> to infer structural
JSON-safe return types from entity props, replacing Record<string, unknown>
on toJSON() while keeping normalize() runtime behavior unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>
@changeset-bot

changeset-bot Bot commented Jul 4, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 30ecf60

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@rineex/ddd Minor
@rineex/auth-core Patch
@rineex/authentication-method-otp Patch
@rineex/authentication-method-passwordless Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

pourdaavar and others added 3 commits July 4, 2026 18:52
Co-authored-by: Cursor <cursoragent@cursor.com>
Handle Tagged<UuID> IDs by introducing JsonIdValue and modeling EntityJson
as DeepPrimitive<Props> plus explicit createdAt/id fields. Revert generic
normalize to avoid excessive type instantiation depth in CI.

Co-authored-by: Cursor <cursoragent@cursor.com>
Reorganized import statements in entity.ts for clarity and consistency. Updated the JsonPrimitive type definition in deep-primitive.type.ts to maintain a consistent order of primitive types.

Co-authored-by: Cursor <cursoragent@cursor.com>
@pourdaavar pourdaavar merged commit 7ce68e1 into main Jul 4, 2026
5 checks passed
@pourdaavar pourdaavar mentioned this pull request Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(ddd): type-safe Entity.toJSON() via DeepPrimitive

1 participant